﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using YJKSparseDisOfRoom.ControlLayer;
using YJKRevitKernel.ShortPathSuite;

namespace YJKSparseDisOfRoom.ModelLayer
{
	public class WayMapBean : BaseWapMapCalculater<EndPointPacker_InRoom>
	{
		public WayMapBean(RoomNodePacker input)
		{
			this.m_useCalculater = new YJKSparseDisOfRoom.ControlLayer.UseGraphCalculater();
			this.m_useCalculaterDel = new GenericShortWayCalculatDel<EndPointPacker_InRoom>(this.UseCalculateMehtod);
			this.m_useMidPointDel = new MidPointUsefulDel(this.CheckPointByRoom);
			this.m_useRoomCurveBean = input.GetCurveBean();
            this.m_lstAllCanNotGoCurves = this.m_useRoomCurveBean.LstWallLocationCurves.Cast<YJKRevitKernel.ShortPathSuite.BaseCurveBean>().ToList<YJKRevitKernel.ShortPathSuite.BaseCurveBean>();
			foreach (CurveBeanUnit curveBeanUnit in this.m_useRoomCurveBean.LstCurveBeanUnit)
			{
				this.m_lstAllCanGoBoundaryCurves.AddRange(curveBeanUnit.LstCurve);
			}
			this.CalculateBulidingLinkWays();
		}

		public bool TryCalculate(out ResultBean_InRoom result)
		{
			result = null;
			bool flag = false;
			List<XYZ> lstPoints;
			base.CalculatePath(out lstPoints, out flag);
			if (flag)
			{
				result = new ResultBean_InRoom(this.m_lstEndPoints[0], this.m_lstEndPoints[1], lstPoints);
			}
			return flag;
		}

		private bool CheckPointByRoom(XYZ tempPoint)
		{
			return this.m_useRoomCurveBean.UseRoomPacker.ThisRoom.IsPointInRoom(tempPoint);
		}

		private void CalculateBulidingLinkWays()
		{
			List<XYZPoint> list = new List<XYZPoint>();
			List<Line> list2 = new List<Line>();
			int num = 0;
			foreach (CurveBeanUnit curveBeanUnit in this.m_useRoomCurveBean.LstCurveBeanUnit)
			{
				foreach (Curve curve in curveBeanUnit.LstInnerLinkCurve)
				{
					list2.Add(curve as Line);
				}
				foreach (BaseCurveBean baseCurveBean in curveBeanUnit.LstCurve)
				{
					list.Add(new XYZPoint(baseCurveBean.ThisCurve.GetEndPoint(0), num));
				}
				num++;
			}
            base.CalculaterLinkWay(list.Cast<YJKRevitKernel.ShortPathSuite.XYZPoint>().ToList<YJKRevitKernel.ShortPathSuite.XYZPoint>(), list2);
		}

		private bool UseCalculateMehtod(EndPointPacker_InRoom startPoint, EndPointPacker_InRoom endPoint, List<Curve> lstCurves, out List<XYZ> shortPath)
		{
			return (this.m_useCalculater as YJKSparseDisOfRoom.ControlLayer.UseGraphCalculater).TryCalculateShortestPath(startPoint, endPoint, lstCurves, out shortPath);
		}

		private RoomCurveBean m_useRoomCurveBean;
	}
}
